import Vue from 'vue';
import dialogVue from './dialog.vue';

let DialogConstructor = Vue.extend(dialogVue);
let dialogInstance = null;

let getInstance = () => {
  if (dialogInstance) {
    return dialogInstance;
  }
  let dom = document.createElement('div');
  dialogInstance = new DialogConstructor({
    el: dom,
  });
  document.body.appendChild(dialogInstance.$el);
  return dialogInstance;
};

const DialogGlobal = () => {
  const instance = getInstance();
  return instance;
};

export default DialogGlobal();
